// pages/home/home.js
const myfunc = require('../../utils/myfunc.js')
var app=getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    sendType:"pickup",
    left_click_flag:false,
    imgUrls: [  
      '../../image/swipe1.jpg',
        '../../image/swipe2.jpg',
        '../../image/swipe3.jpg'
    ],
    indicatorDots: true, //是否显示面板指示点
    autoplay: true, //是否自动播放
    interval: 3000, //停留时间间隔
    duration: 1000, //播放时长
    // previousMargin: '50px', //前边距，可用于露出前一项的一小部分，接受 px 和 rpx 值
    // nextMargin: '50px', //后边距，可用于露出后一项的一小部分，接受 px 和 rpx 值
    circular: false, //是否采用衔接滑动
    currentSwiperIndex: 0, //swiper当前索引
    scrollLength:0,
    tabs:[],
    tabsList:[],
    tabs: [
      {title: '门窗', anchor: 'a', sublist:[{subtitle:"中亿丰罗普斯金",subanchor:"a1"},{subtitle:"门窗品牌2",subanchor:"a2"},{subtitle:"门窗品牌3",subanchor:"a3"}],hideHidden: true},
      {title: '阳台', anchor: 'b',sublist:[{subtitle:"阳台品牌1",subanchor:"b1"},{subtitle:"阳台品牌2",subanchor:"b2"},{subtitle:"阳台品牌3",subanchor:"b3"}],hideHidden: true},
      {title: '全屋定制', anchor: 'c',sublist:[{subtitle:"全屋品牌1",subanchor:"c1"},{subtitle:"全屋品牌2",subanchor:"c2"},{subtitle:"全屋品牌3",subanchor:"c3"}],hideHidden: true},
      {title: '窗帘', anchor: 'd', sublist:[{subtitle:"窗帘品牌1",subanchor:"d1"},{subtitle:"窗帘品牌2",subanchor:"d2"},{subtitle:"窗帘品牌3",subanchor:"d3"}],hideHidden: true},
      {title: '成品家具', anchor: 'e', sublist:[{subtitle:"家具品牌1",subanchor:"e1"},{subtitle:"家具品牌2",subanchor:"e2"},{subtitle:"家具品牌3",subanchor:"e3"}],hideHidden: true},
      {title: '智能灯具', anchor: 'f', sublist:[{subtitle:"灯具品牌1",subanchor:"f1"},{subtitle:"灯具品牌2",subanchor:"f2"},{subtitle:"灯具品牌3",subanchor:"f3"}],hideHidden: true},
      {title: '家用电器', anchor: 'g', sublist:[{subtitle:"电器品牌1",subanchor:"g1"},{subtitle:"电器品牌2",subanchor:"g2"},{subtitle:"电器品牌3",subanchor:"g3"}],hideHidden: true},
      {title: '净化涂料', anchor: 'h', sublist:[{subtitle:"涂料品牌1",subanchor:"h1"},{subtitle:"涂料品牌2",subanchor:"h2"},{subtitle:"涂料品牌3",subanchor:"h3"}],hideHidden: true},
    ],
    tabsList: {
      a: [[{
        price: 10.1, anchor: "a",subanchor:"a1", index: 0, num: 0 , thumbnail:"../../image/12.jpg", sale_name:"中亿丰罗普斯金"
      }, 
      {
        price: 10.1, anchor: "a",subanchor:"a1", index: 0, num: 0 , thumbnail:"../../image/flower.jpg", sale_name:"中亿丰罗普斯金"
      },
      {
        price: 10.1, anchor: "a",subanchor:"a1", index: 0, num: 0 , thumbnail:"../../image/flower.jpg", sale_name:"中亿丰罗普斯金"
       }],
       [{
        price: 10.2, anchor: "a",subanchor:"a2", index: 1, num: 0, thumbnail:"../../image/12.jpg", sale_name:"门窗品牌2"
      },{
        price: 10.2, anchor: "a",subanchor:"a2", index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"门窗品牌2"
      },{
        price: 10.2, anchor: "a",subanchor:"a2", index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"门窗品牌2"
      }],
      [{
        price: 10.3, anchor: "a", subanchor:"a3", index: 2,num: 0, thumbnail:"../../image/12.jpg", sale_name:"天台西餐3"
      },{
        price: 10.3, anchor: "a", subanchor:"a3", index: 2,num: 0, thumbnail:"../../image/flower.jpg", sale_name:"天台西餐3"
      },{
        price: 10.3, anchor: "a", subanchor:"a3", index: 2,num: 0, thumbnail:"../../image/flower.jpg", sale_name:"天台西餐3"
      }]
      ],
      b: [[{
        price: 10.4, anchor: "b",subanchor:"b1", index: 0, num: 0, thumbnail:"../../image/2.jpg", sale_name:"法式三文鱼套餐1"
      },{
        price: 10.4, anchor: "b",subanchor:"b1",  index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"法式三文鱼套餐1"
      },{
        price: 10.4, anchor: "b", subanchor:"b1", index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"法式三文鱼套餐1"
      }], [{
        price: 10.5, anchor: "b", subanchor:"b2", index: 1, num: 0, thumbnail:"../../image/2.jpg", sale_name:"法式三文鱼套餐2"
      },{
        price: 10.5, anchor: "b",subanchor:"b2",  index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"法式三文鱼套餐2"
      },{
        price: 10.5, anchor: "b", subanchor:"b2", index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"法式三文鱼套餐2"
      }],
      [{
        price: 10.6, anchor: "b",subanchor:"b3", index: 2, num: 0,thumbnail:"../../image/2.jpg", sale_name:"法式三文鱼套餐3"
      },{
        price: 10.6, anchor: "b",subanchor:"b3", index: 2, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"法式三文鱼套餐3"
      },{
        price: 10.6, anchor: "b",subanchor:"b3", index: 2, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"法式三文鱼套餐3"
      }]],
      c: [[{
        price: 10.7, anchor: "c",subanchor:"c1", index: 0, num: 0, thumbnail:"../../image/3.jpeg", sale_name:"瑞士奶酪丸子1"
      },{
        price: 10.7, anchor: "c",subanchor:"c1", index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"瑞士奶酪丸子1"
      },{
        price: 10.7, anchor: "c",subanchor:"c1", index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"瑞士奶酪丸子1"
      }], [{
        price: 10.8, anchor: "c",subanchor:"c2", index: 1, num: 0, thumbnail:"../../image/3.jpeg", sale_name:"瑞士奶酪丸子2"
      },{
        price: 10.8, anchor: "c",subanchor:"c2", index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"瑞士奶酪丸子2"
      },{
        price: 10.8, anchor: "c",subanchor:"c2", index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"瑞士奶酪丸子2"
      }],
      [{
        price: 10.9, anchor: "c", subanchor:"c3",index: 2, num: 0, thumbnail:"../../image/3.jpeg", sale_name:"瑞士奶酪丸子3"
      },{
        price: 10.9, anchor: "c", subanchor:"c3",index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"瑞士奶酪丸子3"
      },{
        price: 10.9, anchor: "c", subanchor:"c3",index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"瑞士奶酪丸子3"
      }]],
      d: [[{
        price: 11.0, anchor: "d", subanchor:"d1",index: 0, num: 0,thumbnail:"../../image/4.jpeg", sale_name:"五香酱牛肉1"
      },{
        price: 11.0, anchor: "d", subanchor:"d1",index: 0, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"五香酱牛肉1"
      },{
        price: 11.0, anchor: "d", subanchor:"d1",index: 0, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"五香酱牛肉1"
      }], [{
        price: 11.1, anchor: "d",  subanchor:"d2",index: 1, num: 0, thumbnail:"../../image/4.jpeg", sale_name:"五香酱牛肉2"
      },{
        price: 11.1, anchor: "d",  subanchor:"d2",index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"五香酱牛肉2"
      },{
        price: 11.1, anchor: "d",  subanchor:"d2",index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"五香酱牛肉2"
      }],
      [{
        price: 11.2, anchor: "d",  subanchor:"d3",index: 2, num: 0, thumbnail:"../../image/4.jpeg", sale_name:"五香酱牛肉3"
      },{
        price: 11.2, anchor: "d",  subanchor:"d3",index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"五香酱牛肉3"
      },{
        price: 11.2, anchor: "d",  subanchor:"d3",index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"五香酱牛肉3"
      }]],
      e: [[{
        price: 11.3, anchor: "e",subanchor:"e1", index: 0, num: 0, thumbnail:"../../image/5.jpeg", sale_name:"海南鸡饭1"
      },{
        price: 11.3, anchor: "e",subanchor:"e1", index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"海南鸡饭1"
      },{
        price: 11.3, anchor: "e",subanchor:"e1", index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"海南鸡饭1"
      }], [{
        price: 11.4, anchor: "e",subanchor:"e2", index: 1, num: 0, thumbnail:"../../image/5.jpeg", sale_name:"海南鸡饭2"
      },{
        price: 11.4, anchor: "e",subanchor:"e2", index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"海南鸡饭2"
      },{
        price: 11.4, anchor: "e",subanchor:"e2", index: 1, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"海南鸡饭2"
      }],
      [{
        price: 11.5, anchor: "e", subanchor:"e3",index: 2, num: 0, thumbnail:"../../image/5.jpeg", sale_name:"海南鸡饭3"
      },{
        price: 11.5, anchor: "e", subanchor:"e3",index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"海南鸡饭3"
      },{
        price: 11.5, anchor: "e", subanchor:"e3",index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"海南鸡饭3"
      }]],
      f: [[{
        price: 11.6, anchor: "f",subanchor:"f1", index: 0, num: 0, thumbnail:"../../image/6.jpg", sale_name:"韩国烤肉1"
      },{
        price: 11.6, anchor: "f",subanchor:"f1", index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉1"
      },{
        price: 11.6, anchor: "f",subanchor:"f1", index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉1"
      }], [{
        price: 11.7, anchor: "f", subanchor:"f2",index: 1, num: 0,thumbnail:"../../image/6.jpg", sale_name:"韩国烤肉2"
      },{
        price: 11.7, anchor: "f", subanchor:"f2",index: 1, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉2"
      },{
        price: 11.7, anchor: "f", subanchor:"f2",index: 1, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉2"
      }],
      [{
        price: 11.8, anchor: "f",subanchor:"f3", index: 2, num: 0, thumbnail:"../../image/6.jpg", sale_name:"韩国烤肉3"
      },{
        price: 11.8, anchor: "f",subanchor:"f3", index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉3"
      },{
        price: 11.8, anchor: "f",subanchor:"f3", index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉3"
      }]],
      g: [[{
        price: 11.6, anchor: "g", subanchor:"g1",index: 0, num: 0, thumbnail:"../../image/7.jpeg", sale_name:"韩国烤肉1"
      },{
        price: 11.6, anchor: "g", subanchor:"g1",index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉1"
      },{
        price: 11.6, anchor: "g", subanchor:"g1",index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉1"
      }], [{
        price: 11.7, anchor: "g",subanchor:"g2", index: 1, num: 0,thumbnail:"../../image/7.jpeg", sale_name:"韩国烤肉2"
      },{
        price: 11.7, anchor: "g",subanchor:"g2", index: 1, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉2"
      },{
        price: 11.7, anchor: "g",subanchor:"g2", index: 1, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉2"
      }],
      [{
        price: 11.8, anchor: "g",subanchor:"g3", index: 2, num: 0, thumbnail:"../../image/7.jpeg", sale_name:"韩国烤肉3"
      },{
        price: 11.8, anchor: "g",subanchor:"g3", index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉3"
      },{
        price: 11.8, anchor: "g",subanchor:"g3", index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉3"
      }]],
      h: [[{
        price: 11.6, anchor: "h",subanchor:"h1", index: 0, num: 0, thumbnail:"../../image/8.jpg", sale_name:"韩国烤肉1"
      },{
        price: 11.6, anchor: "h",subanchor:"h1", index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉1"
      },{
        price: 11.6, anchor: "h",subanchor:"h1", index: 0, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉1"
      }], [{
        price: 11.7, anchor: "h", subanchor:"h2",index: 1, num: 0,thumbnail:"../../image/8.jpg", sale_name:"韩国烤肉2"
      },{
        price: 11.7, anchor: "h", subanchor:"h2",index: 1, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉2"
      },{
        price: 11.7, anchor: "h", subanchor:"h2",index: 1, num: 0,thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉2"
      }],
      [{
        price: 11.8, anchor: "h",subanchor:"h3", index: 2, num: 0, thumbnail:"../../image/8.jpg", sale_name:"韩国烤肉3"
      },{
        price: 11.8, anchor: "h",subanchor:"h3", index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉3"
      },{
        price: 11.8, anchor: "h",subanchor:"h3", index: 2, num: 0, thumbnail:"../../image/flower.jpg", sale_name:"韩国烤肉3"
      }]]
    },
    tmp_tabList:{},
    indexId: 0,
    toTitle:"title-c",
    scrollTop:0,
    top:[],
    //distance_array:[],
    distance_array:[{"note":"不说了 都知道","imgs":"123123123/16487439630370629.jpg","address":"扬州市文昌阁","feature":"炸鸡 汉堡","phone":"15052526655","latitude":"32.39444","name":"肯德基（万家福店）","id":4,"state":1,"workTime":"00:00 - 24:00","longitude":"119.433617","callman":"史先生"},{"note":"123","imgs":"123123123/16490872905490885.jpg,123123123/16490872950659726.jpg","address":"123","feature":"123","phone":"123","latitude":"32.394294","name":"123","id":10,"state":2,"workTime":"123","longitude":"119.412640","callman":"123"}],
    addressSelect:true,  //选择附近的额店铺的 模板组件true 为影藏 false为展现
    cur_id:"",  //当前选择的店铺id
    cur_distance_str:"", 
    cur_name:"扬州市广陵店",
    cur_shop_info:"",
    cur_detail:"",  //弹出的选奶茶类型蒙版 改款奶茶当前的详细信息
    milkteaSelectHide:true,  //弹出的选奶茶类型蒙版 默认是影藏true
    tea_config:[{name:"规格", text:["中杯", "", ""]}]
   

  },

    //子类不点击事件
    subitemclick(e){
      let that = this 
      
      // 获取索引值
      let anchor = e.currentTarget.dataset.subanchor;

      // console.log("subanchor="+anchor)

      that.setData({    
        toTitle: "title-" + anchor    
      });
    },

     // 左侧点击事件
    jumpIndex(e) {
      let that = this 

      // 获取索引值
      var index = e.currentTarget.dataset.menuindex   

      let anchor = e.currentTarget.dataset.anchor

      let actionSheet = []      
      let tabs_arr = that.data.tabs

      console.log(tabs_arr)

      //当前产品类目对应 所有品牌产品
      let tabList_arr = that.data.tabsList[anchor]

      let title = "" //到底是门窗 还是阳台 还是全屋定制
      for(let i = 0; i < tabs_arr.length;i++){
        let tmp_item = tabs_arr[i]
        if(tmp_item.anchor == anchor){
          actionSheet = tmp_item.sublist
          title = tmp_item.title
          break
        }
      }

      let tmp_itemList = ["所有"+title+"品牌"]  //只取文字 用于显示 赋值给 showActionSheet itemList
      actionSheet.forEach(function(item, index){
        tmp_itemList.push(item.subtitle)
      })

      wx.showActionSheet({
        itemList: tmp_itemList,
        success (res) {  
          //tapIndex为0表示所有子品牌 其余为各自子品牌

          let tapIndex = res.tapIndex
          // let keyword = tmp_itemList[tapIndex]

          //当前anchor是知道的
          if(tapIndex == 0){ //0表示比如 门窗类目下的所有子品牌产品
            // let tmp_tabList = {}
            // tmp_tabList = tabList_arr

             for(let i = 0; i < tabs_arr.length;i++){
                let tmp_item = tabs_arr[i]
                if(tmp_item.anchor == anchor){                 
                  that.setData({
                    tmp_tabs:[tmp_item]
                  })
                  // console.log("correct tabs")
                  // console.log(that.data.tmp_tabs)
                  // console.log("correct tabs")
                  break
                }
              }

             let tmp = that.data.tabsList[anchor]             

              let tmp_val = {[anchor]:tmp}
              // console.log("correct*****************************")
              // console.log(tmp_val)
              //  console.log("correct*****************************")
              that.setData({
                tmp_tabList:tmp_val
              })
          }else{
            //某一类目下的 子品牌   
            let cur_brand = tmp_itemList[tapIndex] //当前子品牌文字 比如 门窗品牌1 门窗品牌2 门窗品牌3
              for(let i = 0; i < tabs_arr.length;i++){
                let tmp_item = JSON.parse(JSON.stringify(tabs_arr[i]))  // {title: '门窗', anchor: 'a', sublist:[{subtitle:"门窗品牌1",subanchor:"a1"},{subtitle:"门窗品牌2",subanchor:"a2"},{subtitle:"门窗品牌3",subanchor:"a3"}],hideHidden: true},
                let tabs_sublis = tmp_item.sublist  //[{subtitle:"门窗品牌1",subanchor:"a1"},{subtitle:"门窗品牌2",subanchor:"a2"},{subtitle:"门窗品牌3",subanchor:"a3"}]

                if(tmp_item.anchor == anchor){
                    let tmp_sublist = [tabs_sublis[tapIndex-1]]

                    tmp_item.sublist = tmp_sublist

                    that.setData({
                      tmp_tabs:[tmp_item]
                    })

                    let subanchor = tmp_sublist[0].subanchor  //子anchor

                    let tmp = that.data.tabsList[anchor]   

                    //下面根据subanchor来确定tabsList 数据
                    //双层遍历 tmp = that.data.tabsList[anchor] 根据 subabchor 来确定tabsList的值

                    if(tmp.length == 0||tmp == undefined|| tmp==null){
                        that.setData({
                          tmp_tabList:{}
                        })
                    }
                    for(let m = 0; m < tmp.length;m++){
                       let tmp_item = tmp[m]
                       let flag_tmp_item =  tmp_item[0]
                   


                      if(flag_tmp_item.subanchor == subanchor){
                          let tmp_item_arr = []
                          tmp_item_arr.push(tmp_item)
                          let tmp_val = {[anchor]:tmp_item_arr}
                          
                          that.setData({
                            tmp_tabList:tmp_val
                          })

                          break
                      }
                    }
                   break         
                }           
              }
          }
        },
        fail (res) {
             console.log("sheetAction error")   
          console.log(res.errMsg)
        }
      })
    
      //  //原来是打开二级菜单 现在改成用showActionSheet从底部弹出框
      // var index = e.currentTarget.dataset.menuindex;
       // 获取当前的状态，是否隐藏的值
      //  var staues = that.data.tabs[index].hideHidden;     
      
      //  // 第几个状态
      //  var stauesval = "tabs[" + index + "].hideHidden";
      //  if (staues == true) {
      //    that.setData({
      //      [stauesval]: false
      //    })
      //  } else {
      //    that.setData({
      //      [stauesval]: true
      //    })
      //  }


      //单层按钮时的逻辑
      // let index = e.currentTarget.dataset.menuindex;
      console.log("index="+index)
      //let anchor = e.currentTarget.dataset.anchor;
      //console.log("anchor="+anchor)
      // let that = this
      that.setData({
        indexId: index,
        toTitle: "title-" + anchor,
        left_click_flag:true
      });
      //可以设置定位事件
    },
  
    //这个其实是下拉或者上啦右侧部分滚动触发的函数
    //滚动时触发，event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}
    scrollToLeft(res){
      //{"type":"scroll","timeStamp":5101281,"target":{"id":"","offsetLeft":111,"offsetTop":1,"dataset":{}},"currentTarget":{"id":"","offsetLeft":111,"offsetTop":1,"dataset":{}},"mark":{},"detail":{"scrollLeft":0,"scrollTop":1047,"scrollHeight":2094,"scrollWidth":337,"deltaX":0,"deltaY":321},"mut":false,"_userTap":false}
      if(this.data.left_click_flag){
        this.setData({
          left_click_flag:false
        })
        return;
      }
   
      this.setData({
        scrollTop: res.detail.scrollTop
      })
      var length = this.data.top.length;
      for(var i=0;i<this.data.top.length;i++){
        // [1,350,699,1048,1397,1746]
        if (this.data.top[i] - this.data.top[0] <= this.data.scrollTop && (i < length  && this.data.top[i + 1] - this.data.top[0] > this.data.scrollTop)){
         if(this.data.indexId!=i){        
            this.setData({
              indexId: i,
            }); 
          }
        }
      }
      // console.log("top:"+top);
    },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this
    //第一步请求数据，设置成指定的数据格式，初始化界面
    //step1 请求店铺
      //获取当前用户地址
      wx.getLocation({
        type: 'wgs84',
        success(res) {
            const latitude = res.latitude         
            wx.setStorageSync('latitude', latitude)
            const longitude = res.longitude         
            wx.setStorageSync('longitude', longitude)          
            const speed = res.speed
            const accuracy = res.accuracy
            wx.request({
                method:"post",      
                url: app.globalData.url_suffix+'/FrontFindStore',
                data:{
                    appid:app.globalData.appid
                },
                header: {
                    'content-type': 'application/x-www-form-urlencoded',
                },  
                success:function(res){
                    let result_str = res.data.data
                    let lng1= wx.getStorageSync('longitude')
                    let lat1 = wx.getStorageSync('latitude')
                    // "[{"note":"不说了 都知道","imgs":"123123123/16487439630370629.jpg","address":"扬州市文昌阁","feature":"炸鸡 汉堡","phone":"15052526655","latitude":"32.39444","name":"肯德基（万家福店）","id":4,"state":1,"workTime":"00:00 - 24:00","longitude":"119.433617","callman":"史先生"},{"note":"123","imgs":"123123123/16490872905490885.jpg,123123123/16490872950659726.jpg","address":"123","feature":"123","phone":"123","latitude":"32.394294","name":"123","id":10,"state":2,"workTime":"123","longitude":"119.412640","callman":"123"}]"
                    let shop_arr = JSON.parse(result_str);
                    let distance_array = [] 
                    let online = false  

                    shop_arr.forEach(element => {
                        let lng2 = element.longitude
                        let lat2 = element.latitude        
                        let distance = myfunc.getDistance(lat1, lng1, lat2, lng2)

                        let worktime = element.workTime;

                        //测试补丁，给的worktime居然有123的值
                        if(worktime.indexOf("-")==-1){
                          online = true                         
                        }else{
                          let timeperiod = worktime.split("-")                       
                          let begintime = timeperiod[0].trim()
                          let endtime = timeperiod[1].trim()  
                          online = myfunc.time_range_now(begintime, endtime)                    
                        }

                        let distance_str = "";
                        if(distance>1000){
                          let tmp = distance/1000
                          distance_str = tmp.toFixed(1)+"公里"
                        }else{
                          distance_str = distance+"米"
                        }
                       
                        distance_array.push({
                            "distance":distance, //这个distance值使用来排序的
                            "distance_str":distance_str,  //这个distance_str是用来显示的
                            "id":element.id,
                            "latitude":element.latitude,
                            "longitude":element.longitude,
                            "note":element.note,
                            "address":element.address,
                            "feature":element.feature,
                            "phone":element.phone,
                            "name":element.name,
                            "state":element.state,
                            "workTime":element.workTime,
                            "callman":element.callman,
                            "online":online
                        })
                    });  

                    distance_array.sort(that.compare('distance')); //根据distance属性来排序

                    that.setData({
                        //distance_array:distance_array
                        distance_array:[{"note":"不说了 都知道","imgs":"123123123/16487439630370629.jpg","address":"扬州市文昌阁","feature":"炸鸡 汉堡","phone":"15052526655","latitude":"32.39444","name":"肯德基（万家福店）","id":4,"state":1,"workTime":"00:00 - 24:00","longitude":"119.433617","callman":"史先生"},{"note":"123","imgs":"123123123/16490872905490885.jpg,123123123/16490872950659726.jpg","address":"123","feature":"123","phone":"123","latitude":"32.394294","name":"123","id":10,"state":2,"workTime":"123","longitude":"119.412640","callman":"123"}]
                    })
                }
            })
        }
    })
    
    wx.getSystemInfo({
      success: function (res) {
        //暂时不需要
        // that.setData({
        //   winHeight: res.windowHeight
        // });
        // var top2=new Array();
        // for(var i=0;i<that.data.tabs.length;i++){
        //   wx.createSelectorQuery().select('#view-' + that.data.tabs[i].anchor).boundingClientRect(function (rect) {           
        //     var isTop = Number(rect.top);           
        //     top2.push(isTop);    
        //   }).exec();          
        // }  
        // that.setData({
        //   top: top2  //就是右边各个区块的分类的块的top值，比如特惠部分对应的右边3个组成一个块的top值是1，必点项目右边几个小块组成的一个大块的top值是350
        // });
      }      
    });    

    let tmp = that.data.tabsList.a

    console.log({a:tmp})

    that.setData({
      tmp_tabList:{a:tmp}
    })

    let tmp2 = that.data.tabs[0]

    that.setData({
      tmp_tabs:[tmp2]
    })
  },

  clicktelephone:function(e){
    let that = this
    let tel = e.currentTarget.dataset.tel
  
    wx.makePhoneCall({
      phoneNumber: tel //仅为示例，并非真实的电话号码
    })
  },

  clicknavigator:function(e){
    let that = this  
    let latitude = JSON.parse(e.currentTarget.dataset.latitude)   
  
    let longitude = JSON.parse(e.currentTarget.dataset.longitude)     
  
    let name = e.currentTarget.dataset.name    
    //console.log(name)
    let address = e.currentTarget.dataset.address   
    //console.log(address)
    wx.openLocation({ 
      latitude: latitude,      
      longitude:longitude,      
      name: name,      
      address: address,      
      scale: 20      
    })
  },

  //选择店铺 绑定的函数
  gotoShop:function(e){
    let that = this
    console.log(e.currentTarget.dataset)
    let distance_array = that.data.distance_array;
    let id = e.currentTarget.dataset.id   //店铺Id
    wx.setStorage({
      shopID:id
    })
    
    let distance_str = e.currentTarget.dataset.distance_str   
    let name = e.currentTarget.dataset.name 
    distance_array.forEach(function(item, index){
      if(item.id == id){
        that.setData({
          cur_shop_info:item
        })
        return false
      }
    })

    that.setData({
      addressSelect:true,
      cur_distance_str:distance_str,
      cur_id:id,
      cur_name:name
    })   

    //选择好店铺后，店铺id确定下来了，就可以请求 左侧分类以及右侧具体内容
    wx.request({
        method:"post",  
            url:app.globalData.url_suffix+"/FrontFindClass",
            data: {             
                appid: app.globalData.appid,   
                storeId:id
            },  
            header: {
                'content-type': 'application/x-www-form-urlencoded',                
            },  
            success: res => {
                //图片绝对地址 https://admin.yzqysoft.com/goods/123123123/16490882372860619.jpg 即app.globalDatawx.url_suffix+'/123123123/16487439630370629.jpg'
                //{"data":"[{\"note\":\"\",\"img\":\"123123123/16490882372860619.jpg\",\"enable\":1,\"father\":0,\"name\":\"奶茶\",\"id\":28,\"sort\":0,\"storeId\":4}]","error":200}  id为类别id  storeId为店铺id
                if(res.data.error == 200){ //返回正确
                    let category_array = JSON.parse(res.data.data)
                    //重新组织数据 tabs: [{title: '特惠', anchor: 'a', },{title: '必点', anchor: 'b', },...]
                    let tmp_taps_array = []
                    category_array.forEach(function(item, index){
                        let tmp = {}
                        tmp.title = item.name
                        tmp.anchor = item.id  //锚点就设置为 该类型的id
                        tmp.note = item.note
                        tmp.img = app.globalData.url_suffix+"/"+item.img
                        tmp.enable = item.enable
                        tmp.father = item.father
                        tmp.categoryID = item.id
                        tmp.sort = item.sort
                        tmp.storeId = item.storeId
                        tmp_taps_array.push(tmp)
                    })

                    let other_array ={
                      title:"其它",
                      anchor:"*",
                      note:"",
                      img:"",
                      enable:1,
                      father:0,
                      categoryID:"*",
                      sort:0,
                      storeId:id, //店铺id
                    }

                    tmp_taps_array.push(other_array)
                    that.setData({
                        tabs:tmp_taps_array
                    })    
                    
                    //先用数组记录所有的分类 如
                    //tabsList: {
                      //a: [{
                      //     price: 10.1, anchor: "a", index: 0, num: 0 , thumbnail:"../../image/1.jpg", sale_name:"天台西餐1"
                      //   }],
                      //   b: [{
                      //     price: 10.4, anchor: "b", index: 0, num: 0, thumbnail:"../../image/2.jpg", sale_name:"法式三文鱼套餐1"
                      //   }]
                    let  tmp_tabsList = {}
                    let anchor_array = []  //纯分类数组 ['a','b', 'c', 'd']
                    tmp_taps_array.forEach(function(item, index){
                      anchor_array.push(item.anchor)
                      tmp_tabsList[item.anchor] = []
                    })

                    //console.log(tmp_tabsList) //{'28': [], '*': []}                    
                    //分类也请求到了，这个时候请求所有分类下面的所有商品                   
                    wx.request({
                        method:"post",  
                        url:app.globalData.url_suffix+"/FrontFindGoods",
                        data: {             
                            appid: app.globalData.appid,   
                            storeId:tmp_taps_array[0].storeId,
                            classId:-1,
                            PageIndex:0,
                            PageSize:99
                        },  
                        header: {
                            'content-type': 'application/x-www-form-urlencoded',
                        },  
                        success: res => {
                            let result = res.data
                            //console.log("res.data="+JSON.parse(res.data))
                            if(result.length != 0){//代表返回正确    
                              //先根据类别来分类
                              result.forEach(function(item, index){
                                //这里先把img解析一下
                                let imgs = JSON.parse(item.imgs)
                               
                                let imgs_thumbnail = ""
                                if(imgs.length !=0){                               
                                  imgs_thumbnail = app.globalData.url_suffix+ "/" +imgs[0].url
                                  item.thumbnail = imgs_thumbnail
                                }else{
                                  item.thumbnail = "/images/unknown_milktea.png"
                                }                                
                                let tmp_tab = item                                
                                let classId=item.selectedClass                               
                                if(tmp_tabsList[classId] == undefined){
                                  tmp_tabsList["*"].push(tmp_tab)
                                }else{
                                  tmp_tabsList[item.selectedClass].push(tmp_tab)
                                }
                              })                            
                              that.setData({
                                tabsList:tmp_tabsList
                              })
                            }else{

                            }  
                        }
                    })
                }else{
              
                }                        
            }
    })
  },

  gotoShopDetail:function(){
    let that = this
    let cur_shop_info = that.data.cur_shop_info
    let cur_shop_info_str = JSON.stringify(cur_shop_info)

    wx.navigateTo({
      url: '../shopDetail/shopDetail?cur_shop_info='+cur_shop_info_str
    })
  },

  /**电机切换店铺按钮 重新弹出选择店铺窗口 */
  change_shop:function(){
      let that = this

      that.setData({
        addressSelect:false
      })
  },


 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.bindAnimation();
  },

   //选择门店
   selectShop(){
    let that = this
    let distance_arr = that.data.distance_array
},

bindAnimation(){
  var this_ = this;
  var animation = wx.createAnimation({
      duration: 5000,
      timingFunction: 'linear',
      transformOrigin:"100% 0 0"
    })
  animation.translateX('-100%').step();
  this.setData({
    animation:animation.export(),
  })
  //设置循环动画
  this.animation = animation;
  setInterval(function(){
    //第二个动画 文字位置初始化
    this.Animation2();

    //延迟播放滚动动画（效果会更好点）
    setTimeout(function(){
      this.animation.translateX('-100%').step();
      this.setData({
        animation: animation.export(),
      })
    }.bind(this),100); 
      
  }.bind(this),5000);  
},

/**
 * 第二个动画 文字位置初始化
 */
Animation2(){
  var this_ = this;
  var animation2 = wx.createAnimation({
    duration: 0,
    timingFunction: 'linear',
    transformOrigin:"100% 0 0"
  })
  animation2.translateX('100%').step();
  this_.setData({
    animation:animation2.export(),
  })
},
                  
  compare(property) {//property:根据什么属性排序
      return function(a,b){
          var value1 = a[property];
          var value2 = b[property];
          /*
          * value2 - value1; ——> 降序
          * value1 - value2; ——> 升序
          */
          return value1 - value2;//升序排序
      }
 },

//传到模板里的方法，修改奶茶数量
reduceFood:function(e){
  console.log(e)
  let that = this
  let cur_tabsList = that.data.tabsList

  let anchor = e.currentTarget.dataset.anchor //anchor就是我们数组里面的selectedClassId
  let goodid = e.currentTarget.dataset.goodid

  let cur_detail = "";

  let current_item = cur_tabsList[anchor]
  current_item.forEach(function(item, index){
    if(item.GoodId == goodid){
      cur_detail = item
      that.setData({
        cur_detail:cur_detail
      })
      return false
    }
  })
},

clickItem:function(e){
  let that = this
  //dataset: {anchor: 28, goodid: "08afb6fb-c52c-4f42-a4c5-aa53bc21c275"}里面有这些信息
  let GoodInfo = e.currentTarget.dataset
  let goodid = GoodInfo.goodid
 
  wx.navigateTo({
    url: '../productDetail/productDetail?goodid='+goodid,
  })
},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
     //解决小程序退出、隐藏后台动画停止
    //重新触发动画方法即可
    this.bindAnimation();

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})